#!/bin/bash
# Program:
#	Configure Ubuntu
#
#	Conditions:
#	   UbuntuKylin
#	   Kernel 3.8.0
#
# History:
#     2014/04/10 Potter  Version 1.1

if [ -f "cu.log" ]
then
    mv cu.log cu.log.old
fi
touch cu.log

cp /etc/apt/sources.list /etc/apt/sources.list.old

echo "deb http://debian.ustc.edu.cn/ubuntu/ raring main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ raring-backports main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ raring-proposed main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ raring-security main multiverse restricted universe
deb http://debian.ustc.edu.cn/ubuntu/ raring-updates main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ raring main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ raring-backports main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ raring-proposed main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ raring-security main multiverse restricted universe
deb-src http://debian.ustc.edu.cn/ubuntu/ raring-updates main multiverse restricted universe" > /etc/apt/sources.list

apt-get update || echo "error: apt-get update failed." >> cu.log

# Bradcom 802.11 Linux STA 无线网卡驱动
apt-get install -y bcmwl-kernel-source && \
apt-get install -y broadcom-sta-common && \
apt-get install -y broadcom-sta-common && \
apt-get install -y broadcom-sta-source && \
# Broad 43xx 固件提取工具
apt-get install -y b43-fwcutter && \
apt-get install -y firmware-b43-installer && \
# 激活无线网卡
modprobe -r b43 ssb && \
modprobe b43  || echo "error: 无线网卡安装失败." >> cu.log

# 调教Nvidia驱动
# http://wiki.ubuntu.org.cn/NVIDIA
# https://github.com/Bumblebee-Project/Bumblebee
# https://launchpad.net/~bumblebee/+archive/stable
#add-apt-repository ppa:bumblebee/stable && \
#apt-get update && \
#apt-get install -y bumblebee bumblebee-nvidia  
#add-apt-repository ppa:ubuntu-x-swat/x-updates && \
#apt-get update && \
#apt-get install -y nvidia-current nvidia-settings && \
# 从事GPU开发的可能还需要装上cuda和openCL库的支持
#apt-get install -y nvidia-current-dev || echo "error: 安装Nvidia drivers failed." >> cu.log
# "Need reboot
# "The Follow to See how Nvidia Run
# sudo optirun nvidia-settings -c :8
# "To run program using Nvidia
# sudo optirun + program_name
#
#
# add following to /etc/apt/sourcelist
# 12.04 and Me (kernel 3.8)
#	deb http://ppa.launchpad.net/bumblebee/stable/ubuntu precise main 
#	deb-src http://ppa.launchpad.net/bumblebee/stable/ubuntu precise main 
# 
# 13.10:
#	deb http://ppa.launchpad.net/bumblebee/stable/ubuntu saucy main 
#	deb-src http://ppa.launchpad.net/bumblebee/stable/ubuntu saucy main 
#
# 14.04:
#       deb http://ppa.launchpad.net/bumblebee/stable/ubuntu trusty main 
#	deb-src http://ppa.launchpad.net/bumblebee/stable/ubuntu trusty main 
#

# 卸载不需要的程序
# 即时通信
#apt-get -y purge empathy && \
#apt-get -y purge nautilus-sendto-empathy && \
#apt-get -y purge empathy-common && \
# 邮件
#apt-get -y purge thunderbird* && \
# apt-get autoremove indicator-messages && \
# apt-get -y purge gwibber*
# Ubuntu One
#apt-get -y purge ubuntuone* && \
# apt-get -y purge update-* && \
# 打印
#apt-get -y purge hplip* && \
#apt-get -y purge printer-driver* && \
# 问题报告
#apt-get -y purge apport* && \
# 扫描
#apt-get -y purge simple-scan && \
# 崩溃报告
#apt-get -y purge whoopsie && \
#apt-get -y purge samba-common* && \  #samba共享

# 办公套件
# apt-get -y purge libreoffice* && \

# 安装需要的程序
apt-get install -y vim || echo "error: install vim failed" >> cu.log
apt-get install -y gcc  || echo "error: install gcc failed" >> cu.log
apt-get install -y g++ || echo "error: install g++ failed" >> cu.log
# apt-get install -y python && \
# apt-get install -y apcalc && \
apt-get install -y smplayer || echo "error: install smplayer failed." >> cu.log
apt-get install -y git || echo "error: failed to install git" >> cu.log
apt-get install -y ssh || echo "error: failed to install ssh" >> cu.log
apt-get install -y filezilla || echo "error: failed to install filezilla" >> cu.log
apt-get install -y subversion || echo "error: failed to install subversion." >> cu.log
apt-get install -y virtualbox || echo "error: failed to install virtualbox." >> cu.log
apt-get install -y convmv || echo "error: failed to install convmv" >> cu.log
apt-get install -y tree || echo "error: failed to install tree" >> cu.log
# python-setuptools --> easy_install
apt-get install -y python-setuptools || echo "error: failed to install python-setuptools" >> cu.log
# 利用easy_install 安装virtualenv
# easy_install virtualbox
apt-get install -y python-virtualenv || echo "error: failed to install python-virtualenv" >> cu.log
# apt-get install -y 
# apt-get install -y 
# apt-get install -y 

# 安装Brackets.io , html, js
# http://brackets.io
wget -O Brackets.deb https://github.com/adobe/brackets/releases/download/sprint-38/Brackets.Sprint.38.64-bit.deb && \
dpkg -i Brackets.deb || echo "error: failed to install brackets.deb" >> cu.log

# 安装flash插件
apt-get install -y flashplugin-installer || echo "error: failed to install flashplugin" >> cu.log

# 安装 chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get install -y libxss1 && \
dpkg -i google-chrome-stable_current_amd64.deb || \
# apt-get install -y google-chrome-stable && \
# apt-get -f install && \
# dpkg -i google-chrome-stable_current_amd64.deb && \
echo "error: failed to install google-chrome" >> cu.log
rm -rf google-chrome*

# njit-client
apt-get install -y libpcap-dev libssl-dev && \
apt-get install -y pkg-config && \
apt-get install -y automake && \
git clone https://github.com/liuqun/njit8021xclient.git && \
cd njit8021xclient/ && \
./help && \
make && make install && \
cd .. && \
rm -rf njit8021xclie* || echo "error: failed to install njit-client." >> cu.log
rm -rf njit8021x*

# 好用的音乐播放器
wget https://iceplayer.googlecode.com/files/iceplayer-amd64-4.0.5-20110520.deb && \
dpkg -i iceplayer*
# 解决依赖
apt-get -f -y install && dpkg -i iceplayer* || echo "error: failed to install iceplayer." >> cu.log
# 针对ubuntu13.04 kernel 3.8.x 缺少libnotify.so.1
apt-get install -y python-notify
ln -s /usr/lib/x86_64-linux-gnu/libnotify.so.4 /usr/lib/x86_64-linux-gnu/libnotify.so.1

# 安装KDE桌面
# apt-get install kubuntu-desktop || echo "error: failed to install kubuntu-desktop"

# Errors Report:
cat cu.log
rm -rf cu.log*

echo "Reboot 10 seconds later..."
sleep 10

# reboot 


exit 0
